package com.decent.ejfadmin.apply.dao;

import com.decent.ejfadmin.apply.dao.provider.RebateApplyDaoProvider;
import com.decent.ejfadmin.apply.request.RebateApplyQueryParam;
import com.decent.ejfadmin.common.bean.SupRebateApply;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhangchao
 * @date 2018/7/30 15:49
 */
@Mapper
@Repository
public interface RebateApplyDao {

    /**
     * 推荐有礼申请查询总数
     *
     * @param param
     * @return
     */
    @Select("<script>" +
            "select count(1) from yuhuang_sup_rebate_apply where 1=1 " +
            "<if test=\"name != null\"> and name = #{name}</if>" +
            "<if test=\"phone != null\"> and phone = #{phone}</if>" +
            "<if test=\"state != null\"> and state = #{state}</if>" +
            "</script>")
    int queryRebateApplyCount(RebateApplyQueryParam param);

    /**
     * 推荐有礼申请查询分页数据
     *
     * @param param
     * @return
     */
    @SelectProvider(type = RebateApplyDaoProvider.class, method = "queryRebateApplyPage")
    List<SupRebateApply> queryRebateApplyPage(@Param("param") RebateApplyQueryParam param);

    /**
     * 状态变更
     *
     * @param applyId
     * @param state
     */
    @Update("update yuhuang_sup_rebate_apply set state = #{state} where id = #{applyId}")
    void changeState(@Param("applyId") Long applyId, @Param("state") Integer state);

    /**
     * 修改备注
     *
     * @param applyId
     * @param remark
     */
    @Update("update yuhuang_sup_rebate_apply set remark = #{remark} where id = #{applyId}")
    void addRemark(@Param("applyId") Long applyId, @Param("remark") String remark);
}
